package com.appkubes.fintech.admin.task.job;


import com.appkubes.fintech.admin.task.dao.FintechTaskInfoDao;
import com.appkubes.fintech.common.util.SpringContextHolder;
import com.appkubes.fintech.core.po.FintechTaskInfo;
import com.appkubes.fintech.core.po.FintechTaskInfoExample;
import com.appkubes.fintech.core.pojo.FintechTaskInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author jie
 * @date 2019-01-07
 */
@Component
@Slf4j
public class JobRunner implements ApplicationRunner {

    @Autowired
    private FintechTaskInfoDao fintechTaskInfoDao;

    @Autowired
    private QuartzManage quartzManage;

    /**
     * 项目启动时重新激活启用的定时任务
     * @param applicationArguments
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments applicationArguments){
        log.info("--------------------注入定时任务---------------------");
//        FintechTaskInfoMapper taskInfoMapper=   SpringContextHolder.getBean("fintechTaskInfoMapper");
        FintechTaskInfoExample example=new FintechTaskInfoExample();
        example.createCriteria().andStatusEqualTo(1);
        List<FintechTaskInfo> quartzJobs = fintechTaskInfoDao.selectByExample(example);
        quartzJobs.forEach(quartzJob -> {
            quartzManage.addJob(quartzJob);
        });
       log.info("--------------------定时任务注入完成---------------------");
    }
}
